<?php if (!defined('THINK_PATH')) exit(); /*a:1:{s:69:"D:\F\wamp\www\xu_tp5\public/../application/admin\view\user\index.html";i:1513243665;}*/ ?>
<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Document</title>
    <link rel="stylesheet" href="/static/bootstrap/dist/css/bootstrap.min.css">
    <link rel="stylesheet" href="/static/layer/theme/default/layer.css">
    <script src="/static/bootstrap/js/jquery.min.js"></script>
    <script src="/static/admin/js/jquery3.1.1.js"></script>
    <script src="/static/layer/layer.js"></script>
</head>
<body>
    <div class="col-sm-12">
        <button type="button" class="btn btn-info" onclick="addUser()">增加用户</button>
        <table class="table table-striped">
            <thead>
                <tr>
                    <th>用户名ID</th>
                    <th>用户名</th>
                    <th>操作</th>
                </tr>
            </thead>
            <tbody>
            <?php if(is_array($user_list) || $user_list instanceof \think\Collection || $user_list instanceof \think\Paginator): if( count($user_list)==0 ) : echo "" ;else: foreach($user_list as $key=>$vo): ?>
            <tr>

                <td><?php echo $vo->id; ?></td>
                <td><?php echo $vo->username; ?></td>
                <td><button type="button" class="btn btn-primary" onclick="editUser(<?php echo $vo->id; ?>)">编辑</button>
                    <button type="button" class="btn btn-danger" onclick="delUser(<?php echo $vo->id; ?>)">删除</button></td>
            </tr>
            <?php endforeach; endif; else: echo "" ;endif; ?>
            </tbody>

        </table>

    </div>

    <div class="form-horizontal col-sm-12" id="box" style="display: none;margin-top:15px">

        <div class="form-group">
            <label for="user_name" class="col-sm-2 control-label">用户名</label>
            <div class="col-sm-10">
                <input type="text" class="form-control" id="user_name" placeholder="用户名">
            </div>
        </div>
        <div class="form-group">
            <label for="user_pwd" class="col-sm-2 control-label">密码</label>
            <div class="col-sm-10">
                <input type="password" class="form-control" id="user_pwd" placeholder="密码">
            </div>
        </div>
        <div class="form-group">
            <div class="col-sm-offset-6 col-sm-6">
                <button type="button" class="btn btn-default" id="btn">提交</button>
            </div>

        </div>

    </div>
    <!--<script src="/static/bootstrap/dist/js/bootstrap.min.js"></script>-->
    <!--<script src="/static/bootstrap/dist/js/bootstrap.js"></script>-->

    <div class="form-horizontal col-sm-12" id="edit_box" style="display: none;margin-top:15px">

        <div class="form-group">
            <input type="hidden" id="id">
            <label for="user_name" class="col-sm-2 control-label">用户名</label>
            <div class="col-sm-10">
                <input type="text" class="form-control" id="e_user_name" placeholder="用户名">
            </div>
        </div>
        <div class="form-group">
            <label for="user_pwd" class="col-sm-2 control-label">旧密码</label>
            <div class="col-sm-10">
                <input type="password" class="form-control" id="old_user_pwd" placeholder="旧密码">
            </div>
        </div>
        <div class="form-group">
            <label for="user_pwd" class="col-sm-2 control-label">新密码</label>
            <div class="col-sm-10">
                <input type="password" class="form-control" id="new_user_pwd" placeholder="新密码">
            </div>
        </div>
        <div class="form-group">
            <div class="col-sm-offset-6 col-sm-6">
                <button type="button" class="btn btn-default" id="btn_edit">提交</button>
            </div>

        </div>

    </div>



</body>
<script>
    var box;
    //        console.log(layer.open());
    function addUser(){
        box=layer.open({
            title:'增加用户',
            type:1,
            skin:'layer-layer-rim',
            area:['450px','240px'],
            content:$('#box')
        });
    }
    var edit_box;

    $(function(){
        $('#btn').click(function(){
            var user_name =$('#user_name').val();
            var user_pwd =$('#user_pwd').val();
            if(user_name == ''){
                layer.tips('用户名不能为空','#user_name');
                return false;
            }

            if(user_pwd == ''){
                layer.tips('密码不能为空','#user_pwd');
                return false;
            }
            $.post("<?php echo url('admin/user/create'); ?>",{username:user_name,passwd:user_pwd},function(res){
                if(1 == res.code)
                {
                    window.location.reload();

                }else{
                    layer.alert(res.msg,{icon:2,title:'错误提示'});
                }

            },'json');

        });
    });

//
    function editUser(id)
    {
        $.getJSON("<?php echo url('admin/user/edit'); ?>",{id:id},function(res){
            $("#id").val(res.data.id);
            $("#e_user_name").val(res.data.username);
            edit_box=layer.open({
                title:'修改用户',
                type:1,
                skin:'layer-layer-rim',
                area:['450px','240px'],
                content:$('#edit_box')
            });

        })

    }

    function delUser(id)
    {
        layer.confirm('确定删除此用户？',{
            title:'友情提示',
            icon:3,
            closeBtn:0,
            btn:['确定','取消']
        },function(){
            $.getJSON("<?php echo url('admin/user/delete'); ?>",{id:id},function(res){
                if(res.code ==1)
                {
                    window.parent.location.reload();
//                    var index =parent.layer.getFrameIndex(window.name);
//                    console.log(index);
//                    parent.layer.close(index);
//                    window.parent.refresh();
//                    layer.alert(res.msg,{icon:1,title:'删除成功'});
////                    window.location.reload();
//                    location.href="<?php echo url('admin/user/index'); ?>";

                }else{
                    layer.alert(res.msg,{icon:2,title:'提示错误'});
                }

            },function(){

            });
        })

    }
//
    $(function(){
        $('#btn_edit').click(function(){
            var username =$('#e_user_name').val();
            var old_user_pass =$('#old_user_pwd').val();
            var new_user_pass =$('#new_user_pwd').val();
            var id =$('#id').val();
            if(username == ''){
                layer.tips('用户名不能为空','#e_user_name');
                return false;
            }
            $.post("<?php echo url('admin/user/edit'); ?>",{username:username,old_user_pass:old_user_pass,new_user_pass:new_user_pass,id:id},function(res){
                if(res.code ==1){
                    layer.alert(res.msg,{icon:1,title:'修改成功'});
                    window.location.reload();

                }else{
                    layer.alert(res.msg,{icon:2,title:'错误提示'});
                }
            },'json');

        });
    });

</script>
</html>